/**
 * @author Jjn
 * @since 2021-06-12 14:19
 */
public class Solution26_2 {
    
    public int removeDuplicates(int[] nums) {
        int n = nums.length;
        if (n == 0) {
            return 0;
        }
        int fast = 1, slow = 1;
        while (fast < n) {
            if (nums[fast] != nums[fast - 1]) {
                nums[slow] = nums[fast];
                ++slow;
            }
            ++fast;
        }
        return slow;
    }
    
    public static void main(String[] args) {
        Solution26_2 solution262 = new Solution26_2();
        System.out.println(solution262.removeDuplicates(new int[]{1, 2, 3, 4, 5, 3, 3, 2, 1}));
    }
    
}
